package com.tjvib.presenter;

import com.tjvib.util.LogUtil;
import com.tjvib.util.ToastUtil;
import com.tjvib.util.retrofit.ApiInterface;
import com.tjvib.util.retrofit.BaseResponse;
import com.tjvib.util.retrofit.RetrofitHelper;
import com.tjvib.view.activity.LoginActivity;
import com.tjvib.widget.AndroidScheduler;

import io.reactivex.Observer;
import io.reactivex.schedulers.Schedulers;

public class LoginPresenter extends BasePresenter {
    private ApiInterface apiInterface = RetrofitHelper.getInstance().create();

    private static final String TAG = "LoginPresenter";

    public LoginPresenter(LoginActivity view) {
        super(view);
    }

    public void loginBySms(String phone, String code, Observer<BaseResponse> observer) {
        apiInterface.verift_sms_code(phone, code)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidScheduler.mainThread())
                .subscribe(observer);
    }

    public void loginByPwd(String phone, String pwd, Observer<BaseResponse> observer) {
        apiInterface.login_with_phone_number(phone, pwd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidScheduler.mainThread())
                .subscribe(observer);
    }

    public void loginByToken(Observer<BaseResponse> observer) {
        apiInterface.login_with_token()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidScheduler.mainThread())
                .subscribe(observer);
    }

    public void getSmsCode(String phone_number, Observer<BaseResponse> observer) {
        apiInterface.get_sms_code(phone_number)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidScheduler.mainThread())
                .subscribe(observer);
    }

    @Override
    String getTag() {
        return TAG;
    }
}
